package com.dgut.sales.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;



@Controller
public class LoginController {
	
	
	@PostMapping("/saleslogin")
	public String saleslogin(HttpServletRequest request) throws Exception {
		
		String name1 = request.getParameter("name");
		String password = request.getParameter("password");
		request.setAttribute("name1",name1);
			
		if(!name1.equals("HelenYang")) {
			request.setAttribute("NameError1","用户名不存在!");
			return "login/login";
		}
		else {
			if(password.equals("123456")) {
				return "login/salesAdminPage";
			}
			else {
				request.setAttribute("PasswordError1","密码错误");
				return "login/login";
			}
		}	
	}
	
	@PostMapping("/storelogin")
	public String storelogin(HttpServletRequest request) throws Exception {
		
		String name2 = request.getParameter("name");
		String password = request.getParameter("password");
		request.setAttribute("name2",name2);
			
		if(!name2.equals("HelenYang")) {
			request.setAttribute("NameError2","用户名不存在");
			return "login/login";
		}
		else {
			if(password.equals("123456")) {
				return "login/storeAdminPage";
			}
			else {
				request.setAttribute("PasswordError2","密码错误");
				return "login/login";
			}
		}	
	}
	
	@PostMapping("/returnLogin")
	public String returnLogin() {
		return "login/login";
	}

	@GetMapping("/index")
	public String returnIndex() {
		return "index";
	}
}
